package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.PageBean;
import com.itheima.dto.StudentDto;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import com.itheima.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentMapper studentMapper;
    /**
     * 学员分页查询
     *
     * @param dto
     * @return
     */
    @Override
    public PageBean pageGet(StudentDto dto) {
        PageHelper.startPage(dto.getPage(),dto.getPageSize());
        Page<StudentVo> list =   studentMapper.pageGet(dto);
        PageBean bean =  new PageBean(list.getTotal(),list.getResult());
        return bean;
    }

    /**
     * 批量删除学员
     *
     * @param ids
     */
    @Override
    public void deteleByIds(Integer[] ids) {
        for (Integer id : ids) {
            studentMapper.deteleByIds(id);

        }

    }

    /**
     * 添加学员
     *
     * @param student
     */
    @Override
    public void insert(Student student) {
        student.setViolationCount(0);
        student.setViolationScore(0);
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.insert(student);
    }

    /**
     * 根据id查询学员
     *
     * @param id
     * @return
     */
    @Override
    public Student getById(Integer id) {
       Student student =studentMapper.getById(id);
        return student;

    }

    /**
     * 修改员工
     *
     * @param student
     */
    @Override
    public void updateById(Student student) {
        studentMapper.updateById(student);
    }

    /**
     * 违纪处理
     *
     * @param score
     */
    @Override
    public void updateByCount( Integer id ,Integer score) {

        studentMapper.updateByCount(id,score);
    }
}
